var fdata={};
var jsondata;
function init_libres_form(level, wwwroot) {
// Don't need this.	
//    if(newdata){
//        for(var i in newdata){
//		    fdata.push(newdata[i]);
//        }
//	}
    jsondata = YAHOO.lang.JSON.stringify(fdata);
	var url = wwwroot+'/blocks/library_reserve/block_library_reserve_forms.php?level='+level+'&data='+jsondata;
	var AjaxObject = {
		handleSuccess:function (o) {
			document.getElementById('libres-form').innerHTML = o.responseText;
		},

		handleFailure:function (o) {
			alert(o.error+'bla');
		},

		startRequest:function () {
			YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
		}
	};

	var callback = {
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope:AjaxObject
	};

	AjaxObject.startRequest();
}

function get_reserve(id, wwwroot){
	var url = wwwroot+'/blocks/library_reserve/block_library_reserve_forms.php?level=6&get_reserve='+id;
	
	var AjaxObject = {
		handleSuccess:function (o) {
			fdata = YAHOO.lang.JSON.parse(o.responseText);
			init_libres_form(1, wwwroot);
		},

		handleFailure:function (o) {
			alert(o.error+'boom');
		},

		startRequest:function () {
			YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
		}
	};

	var callback = {
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope:AjaxObject
	};

	AjaxObject.startRequest();


}

function set_request_status(id, value, wwwroot){
	for(i=0;i<value.req_status.length;i++){
		if(value.req_status[i].checked==true){
			var selection = value.req_status[i].value;
		}
	}
	var url = wwwroot+'/blocks/library_reserve/block_library_reserve_forms.php?level=7&selection='+selection+'&sel_id='+id;
	
	var AjaxObject = {
		handleSuccess:function (o) {
			document.getElementById('status'+id).innerHTML = o.responseText;
		},

		handleFailure:function (o) {
			alert(o.error+'boom');
		},

		startRequest:function () {
			YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
		}
	};

	var callback = {
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope:AjaxObject
	};

	AjaxObject.startRequest();

}


/*function set_res_type(data){
	var AjaxObject = {
		handleSuccess:function (type) {
			var record = {type:type}
		},

		handleFailure:function (type) {
			alert('An error occurred.');
		},

		startRequest:function () {
			alert(data);
		}
	};

	var callback = {
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.startRequest();
}*/
